package com.itheima.config.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @作者 itcast
 * @创建日期 2020/10/17 16:30
 **/
@WebFilter(urlPatterns = "/actuator/bus-refresh")
public class BusRefreshFilter extends GenericFilter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        // 只要从 requestbody中读取出参数， 后面就没这个参数了
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(request.getInputStream()));
        StringBuilder sb = new StringBuilder();
        bufferedReader.lines().forEach(sb::append);
        System.out.println(sb.toString());
        filterChain.doFilter(request,servletResponse);

    }
}
